﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GNF.Geo;
using System.Collections.ObjectModel;
using GNF.GNFService.GNFClient;

namespace GNF.WPFControls
{
    /// <summary>
    /// Interaction logic for GNFHistoryControl.xaml
    /// </summary>
    public partial class GNFHistoryControl : AbstractGNFUserControl
    {


        #region private memebers

        protected ObservableCollection<GPSData> _GPSDataSource = new ObservableCollection<GPSData>();

        #endregion

        #region contruction and init

        public GNFHistoryControl() : base()
        {
            InitializeComponent();
            HistoryListBox.ItemsSource = _GPSDataSource;
        }

        #endregion

        #region methods

        public override void AbstractGNFUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _client.Connect();
            _client.GPSDataChanged += new TimedOnGPSDataChangedEventHandler(AddNewHistoryItem);
        }

        /// <summary>
        /// change _data memeber to the new "data" that was received
        /// </summary>
        /// <param name="data">the new GPS Data</param>
        /// <param name="changeTime">the time of the GPS Data measurement</param>
        private void AddNewHistoryItem(GPSData data, DateTime changeTime)
        {
            data.TakenAt = changeTime;
            _GPSDataSource.Add(data);
        }

        #endregion


    }
}
